<template>
	<div id='system' v-loading="loading">
		<div class="content-top">
			<span class="h1">业务管理</span>
			<span class="h2">客户需求</span>
		</div>
		<div class="top-btn clearfix">
			<div class="left-content">
				<span class="tip">用户需求</span>
				<el-radio-group v-model="rate" @change = "change()">
					<el-radio :label="1">未分配</el-radio>
					<el-radio :label="2">分配中</el-radio>
					<el-radio :label="3">完毕</el-radio>
				</el-radio-group>
			</div>
			<div class="right-search1">
				<el-input v-model="input" placeholder="输入关键词…"></el-input>
				<el-button  type="primary" @click="look()" style="margin-left: 10px;">查看</el-button>
				<el-button type="primary" @click="excel()">导出excel</el-button>
			</div>
		</div>
		<el-table :data="tableData" style="width: 100%">
			<el-table-column type="index" width="60">
			</el-table-column>
			<el-table-column label="姓名">
				<template slot-scope="scope">
					<span>{{ scope.row.MemberInfo.CNName }}</span>
				</template>
			</el-table-column>
			<el-table-column label="性别">
				<template slot-scope="scope">
					<span>{{ scope.row.MemberInfo.Gender }}</span>
				</template>
			</el-table-column>
			<el-table-column label="手机号">
				<template slot-scope="scope">
					<span>{{ scope.row.MemberInfo.Tel }}</span>
				</template>
			</el-table-column>
			<el-table-column label="电话实名年限">
				<template slot-scope="scope">
					<span>{{ scope.row.MemberInfo.TelYears }}</span>
				</template>
			</el-table-column>
			<!--<el-table-column label="QQ号">
				<template slot-scope="scope">
					<span>{{ scope.row.MemberInfo.QQ }}</span>
				</template>
			</el-table-column>-->
			<el-table-column label="微信号">
				<template slot-scope="scope">
					<span>{{ scope.row.MemberInfo.WX }}</span>
				</template>
			</el-table-column>
			<el-table-column label="需求日期">
				<template slot-scope="scope">
					<span>{{ scope.row.MemberInfo.CreateDate }}</span>
				</template>
			</el-table-column>
			<el-table-column prop="DMoney" label="需求金额">
			</el-table-column>
			<el-table-column prop="AllotAmount" label="分配量">
			</el-table-column>
			<el-table-column prop="DStatus" label="需求状态">
			</el-table-column>
			<el-table-column label="查看">
				<template slot-scope="scope">
					<router-link v-if='scope.row.MemberInfo' v-bind="{to:'/creditInfo/'+(scope.row.MemberInfo.ID)}"><el-button size="mini">风控报告  </el-button></router-link>
					<span v-else></span>
				</template>
			</el-table-column>
			<el-table-column label="操作">
				<template slot-scope="scope">
					<el-button size="mini" type="danger" @click="del(scope.row.ID)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>
		<div class="pages">
			<el-pagination small :current-page="index" @current-change="handleCurrentChange" layout="prev, pager, next" :total="total" background prev-text='上一页' next-text='下一页'>
			</el-pagination>
		</div>
	</div>
</template>

<script>
	import api from '../../../api/api'
	export default {
		name: 'demand',
		data() {
			return {
				loading:true,
				rate: 1, //分配
				input: '', //搜索
				tableData: [],
				total:1,
				index:1,//页码
			}
		},
		created() {
			this.getmdemandlist()
		},
		methods: {
			excel(){
				this.loading = true
				this.$axios.post(api.getmdemandlist,{
				  "Status": this.rate,
				  "pagePara": {
				    "Para": this.input,
				    "PageSize": 10,
				    "PageIndex": this.index-1,
				    "OrderbyString": "CNName",
				    "ToExcel": true
				  }
				}).then(res=>{
					if(res.data.isOK){
						if(res.data.data.ExcelResult && res.data.data.ExcelResult.isOK) {
							this.loading = false
							var urls = res.data.data.ExcelResult.data.filePath
							window.location.href = api.host+'/template/'+urls
						} else{
							this.loading = false
							this.$message.error(res.data.data.ExcelResult.msg);
						}
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/admin'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				})
			},
			handleEdit(index, row) {
				console.log(index, row);
			},
			handleDelete(index, row) {
				console.log(index, row);
			},
			//翻页
			handleCurrentChange(val){
				this.loading = true
				this.index = val
				this.$axios.post(api.getmdemandlist,{
				  "Status": this.rate,
				  "pagePara": {
				    "Para": this.input,
				    "PageSize": 10,
				    "PageIndex": this.index-1,
				    "OrderbyString": "CNName",
				    "ToExcel": false
				  }
				}).then(res=>{
					if(res.data.isOK) {
						this.loading = false
						this.tableData = res.data.data.Data
						this.total = res.data.data.Items
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/admin'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				})
			},
			look(){
				this.getmdemandlist()
			},
			//获取客户需求
			getmdemandlist() {
				this.loading = true
				this.$axios.post(api.getmdemandlist,{
				  "Status": this.rate,
				  "pagePara": {
				    "Para": this.input,
				    "PageSize": 10,
				    "PageIndex": this.index-1,
				    "OrderbyString": "CNName",
				    "ToExcel": false
				  }
				}).then(res=>{
					if(res.data.isOK) {
						this.loading = false
						this.tableData = res.data.data.Data
						this.total = res.data.data.Items
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/admin'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				})
			},
			//删除
			del(id){
				this.loading = true
				this.$axios.get(api.delmdemand +'/'+ id).then(res=>{
		      		if(res.data.isOK){
		      			this.loading = false
		      			this.getmdemandlist()
					}else{
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/admin'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
		      	})
			},
			change(){
				this.loading = true
				this.index = 1
				this.$axios.post(api.getmdemandlist,{
				  "Status": this.rate,
				  "pagePara": {
				    "Para": "",
				    "PageSize": 10,
				    "PageIndex": this.index-1,
				    "OrderbyString": "CNName",
				    "ToExcel": false
				  }
				}).then(res=>{
					if(res.data.isOK) {
						this.loading = false
						this.tableData = res.data.data.Data
						this.total = res.data.data.Items
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/admin'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				})
			}
		}
	}
</script>

<style>

</style>